<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>天气</title>
    <script type="text/javascript" src="../js/vue.js"></script>
    <style>
        *{
            margin-top: 20px;
        }
        .demo1{
            height: 50px;
            background-color: aqua;
        }
    </style>
</head>
<body>
    <div id="root">
        <p>今天天气很：{{weather}}</p>
        <button @click="choose">切换天气</button>
        <hr>
        <p>a：{{number.a}}</p>
        <button @click="number.a++">a++</button>
        <br>
        <p>a：{{number.b}}</p>
        <button @click="number.b++">b++</button>
    </div>


    <script type="text/javascript">
        const vm = new Vue({
            el: "#root",
            data() {
                return {
                    isHot: true,
                    number:{
                        a: 1,
                        b: 1
                    }
                }
            },
            methods: {
                choose(){
                    this.isHot = !this.isHot
                    console.log("isHot 被修改：",this.isHot)
                }
            },
            computed:{
                weather(){
                    return this.isHot ? '炎热':'凉爽'
                } 
            },
            watch: {
                number:{
                    // 深度监视
                    deep:true,
                    handler(newValue,oldValue){
                        setTimeout(() => { //
                            console.log("number修改了，新：", newValue, ", 旧", oldValue)
                        }, 1000);
                    }
                },
                isHot:{
                    immediate: true, // 项目启动的被调用。
                    handler(newValue,oldValue){
                        console.log("天气被修改了，新：", newValue, ", 旧", oldValue)
                    }
                },
                // 简写：
                // isHot(newValue,oldValue){
                //     console.log("天气被修改了，新：", newValue, ", 旧", oldValue)
                // }
            }
        })
        // vm.$watch('tag', { options })
    </script>
</body>
</html>